package com.jiazhong.mingxing.boot.boot09.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

// 书写的拦截器
// 1️⃣ 实现HandlerInterceptor接口
@Component
@Slf4j
public class FirstInterceptor implements HandlerInterceptor {

    // 2️⃣ 重写三个方法
    // 去
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("执行了FirstInterceptor的preHandle方法");
        return true; // true：放行 false：拦截
    }

    // 回
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("执行了FirstInterceptor的postHandle方法");
    }

    // 回
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.info("执行了FirstInterceptor的afterCompletion方法");
    }
}
